<template>
  <div>
  <el-row>
    <el-col :span="6" v-for="one in chapterList" :key="one.id">
      <div class="chapter-list" @click="pushChapterList(one)">
        <el-link :underline="false">{{ one.chapterName }}</el-link>
      </div>
    </el-col>
    <div style="text-align: left">
      <el-button v-if="show" type="info" @click="getChapterListByBookId(currentBook)">点击加载更多</el-button>
    </div>
  </el-row>
  </div>
</template>

<script>
export default {
  name: "chapterList",
  data() {
    return {
      chapterList: [],
      currentBook: {},
      currentPage: 1,
      show: false
    }
  },
  created() {
    const query = this.$route.query;
    this.currentBook = query;
    this.getChapterListByBookId(query);
  },
  methods: {
    pushChapterList(chapter) {
      this.$router.push({
        path: "/chapter/read", query: {
          chapter: chapter,
          bookId: this.currentBook.id
        }
      })
    },
    getChapterListByBookId(book) {
      this.$axios.post("/chapter-message/page", {
        "totalPage": 32,
        "currentPage": this.currentPage,
        "bookId": book.id
      }).then(res => {
        if (res.data.code === '200') {
          this.chapterList = [...this.chapterList, ...res.data.data];
          this.show = res.data.data.length >= 32;
          this.currentPage++;
        } else {
          this.$message.error(res.data.message);
        }
      })
    }
  }
}
</script>

<style scoped>
.chapter-list {
  text-align: left;
  letter-spacing: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 83%;
  color: black;
  line-height: 60px;
  margin-left: 20px;
}

.el-link {
  font-size: 16px;
}

</style>
